package com.tiny.work.biz;

import com.tiny.work.biz.dao.TestMapper;
import com.tiny.work.biz.entity.Test;
import com.tiny.work.biz.entity.TestExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class InjectDaoImp {


  @Autowired
  private TestMapper testMapper;


  @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW,
      rollbackFor = Exception.class)
  public void update() throws InterruptedException {
    TestExample record = new TestExample();
    record.createCriteria().andIdEqualTo(1);
    Test entity = new Test();
    Test dj_tes = new Test();
    dj_tes.setId(1);
    entity.setId(2);
    testMapper.insertSelective(entity);
  }
  @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.NESTED,
      rollbackFor = Exception.class)
  public void nested() throws InterruptedException {
    TestExample record = new TestExample();
    record.createCriteria().andIdEqualTo(1);
    Test entity = new Test();
    Test dj_tes = new Test();
    dj_tes.setId(1);
    entity.setId(2);
//    testMapper.insertSelective(entity);
  }
  @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.NESTED,
      rollbackFor = Exception.class)
  public void nested2() throws InterruptedException {
    TestExample record = new TestExample();
    record.createCriteria().andIdEqualTo(1);
    Test entity = new Test();
    Test dj_tes = new Test();
    dj_tes.setId(1);
    entity.setId(2);
    testMapper.updateByExample(entity, record);
//    testMapper.insertSelective(entity);
  }
}
